package com.qiaoyanqing.textdemoqyq7.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.qiaoyanqing.textdemoqyq7.Beans.Baike;
import com.qiaoyanqing.textdemoqyq7.Beans.Toutiao;
import com.qiaoyanqing.textdemoqyq7.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/14.
 */

public class BaikeAdapter extends BaseAdapter {
    private Context mContext;
    private List<Baike> mdata=new ArrayList<>();


    public BaikeAdapter(Context context, List<Baike> mdata) {
        mContext = context;
        this.mdata = mdata;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int i) {
        return mdata.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertview, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertview == null) {
            holder=new ViewHolder();
            convertview= LayoutInflater.from(mContext).inflate(R.layout.baike,parent,false);
            holder.wap_thumb= (ImageView) convertview.findViewById(R.id.wap_thumb);
            holder.create_time= (TextView) convertview.findViewById(R.id.create_time);
           // holder.description= (TextView) convertview.findViewById(R.id.description);
            holder.nickname= (TextView) convertview.findViewById(R.id.nickname);
            holder.title= (TextView) convertview.findViewById(R.id.title);
            holder.source= (TextView) convertview.findViewById(R.id.source);
            convertview.setTag(holder);
        }else {
            holder= (ViewHolder) convertview.getTag();
        }
        //赋值
        holder.title.setText(mdata.get(position).getTitle());
       // holder.description.setText(mdata.get(position).getDescription());
        holder.source.setText(mdata.get(position).getSource());
        holder.nickname.setText(mdata.get(position).getNickname());
        holder.create_time.setText(mdata.get(position).getCreate_time());
        String path=mdata.get(position).getWap_thumb();
        String pathnotImpty="http://s1.sns.maimaicha.com/images/2015/12/29/20151229093519_45699_suolue3.jpg";
        Picasso.with(mContext).load(path.length()!=0?path:pathnotImpty).into(holder.wap_thumb);
        return convertview;
    }
    static class ViewHolder{
        private TextView title,source,description,create_time,nickname;
        private ImageView wap_thumb;
    }

}
